<template>
    <div>
<h2>登录</h2>
<table class="table">
    <tbody>
        <tr>
            <td>账号</td>
            <td>
                <input type="text" v-model="model.Name" >
            </td>
        </tr>


        <tr>
            <td>密码</td>
            <td>
                <input type="password" v-model="model.Pwd">
            </td>
        </tr>




        <tr>
            <td></td>
            <td>
                <input type="button" value="登录" class="btn  btn-success" @click="ok">
            </td>
        </tr>
    </tbody>
</table>
    </div>
</template>

<script setup lang="ts">

import { ref,reactive } from 'vue';
import { useRoute,useRouter } from 'vue-router';
import axios from 'axios';
const route=useRoute();
const router=useRouter();

//定义变量
let model=reactive({
    
  "Name": '',
  "Pwd": '',
})



//登录
const ok=()=>{

    
if(model.Name==""){
    alert('账号不能为空');
    return;
}

if(model.Pwd==""){
    alert('密码不能为空');
    return;
}




axios({
url:'https://localhost:7009/api/User/Login',
method:'post',
data:model,
})


.then((res)=>{
console.log(res);
if(res.data==0){
    alert('账号不存在');
    return;
}
else if(res.data==-1){
    alert('密码错误');
    return;
}

else{
    alert('登录成功');
    router.push('/UserList')
    return;
}

})




.catch((ree)=>{
console.log(ree);
})






}
</script>

<style scoped>

</style>